import React, { Component } from 'react';
import PropTypes from 'prop-types';

class Todoitem extends Component {
  
  constructor(props){
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  render(){
    const {content} = this.props;
    return (
      <div onClick={this.handleClick}>{content}</div>
    );
  }

  handleClick(){
    const {handleItemDel, index} = this.props;
    handleItemDel(index);
  }
}
// 检测父组件传过来的属性的类型，若没有传该属性，则不检测
// .isRequired用于说明，该属性必须按照制定的数据类型且必须传递
Todoitem.propTypes = {
  test:PropTypes.string.isRequired,
  content:PropTypes.string,
  handleItemDel:PropTypes.func,
  index:PropTypes.number
}

// 若属性没有传递，则将此赋予默认值
Todoitem.defaultProps = {
  test:'hello'
}

export default Todoitem;